#!/bin/bash

# input format like this: "[ezbmc/FRU.c:541]:"

function print_blame_info(){
  echo $1 | awk -F":" '{
    gsub("\[", "", $1);\
    gsub("\]", "", $2);\
    print $1, $2;\
  }' | head -n 1 | while read fn ln
  do
    let offset=3
    let lnum=ln
    let lmin=ln-offset
    let lmax=ln+offset
    svn blame $fn 2>/dev/null | sed -n "$lmin,$lmax"p |\
    awk 'BEGIN{ \
      offset="'"$offset"'"; \
      baseln="'"$lmin"'"; \
    }{\
      if ( NR == offset + 1 ) {\
        print "--> #"baseln, $0;\
      } else {\
        print "    #"baseln, $0;\
      }\
      baseln = baseln + 1;\
    }'
    echo ""
  done
  return
}

cat $1 | while read line
do
  echo $line
  echo $line | awk '{print $1}' | while read fnln
  do
    print_blame_info $fnln
  done
done

